<?php

namespace app\index\controller;


class Index extends \think\Controller
{
    public function __construct()
    {
        parent::__construct();
        $index['css'] = INDEX_CSS;
        $index['js'] = INDEX_JS;
        $index['img'] = INDEX_IMG;
        $index['vendor'] = INDEX_VENDOR;
        $this->assign('index', $index);
        $this->index_limit = INDEX_LIMIT;
    }

    public function index()
    {
        return view();
    }


    /**
     * @return array
     */
    public function news()
    {
        $this->assign('class', 1);
        $id = input('id');
        if ($id) {
            if (is_numeric($id)) {
                $detail = controller('data')->detail($id);
                if ($detail) {
                    $this->assign('detail', $detail);
                    echo $this->fetch("detail");
                } else {
                    $this->error("非法操作");
                }
            } else {
                $this->error("非法操作");
            }
        } else {
            $limit = $this->index_limit;
            $list = controller('data')->news(1, $limit);
            $this->assign('list', $list['data']);
            $this->assign('page', page($list['count'], $limit, 'news'));
            echo $this->fetch("news_list");
        }
    }

    /**
     * @return array
     */
    public function news_append()
    {
        $get = input();
        $limit = $this->index_limit;
        $list = controller('data')->news($get['page'], $limit);
        $this->assign('list', $list['data']);
        $return['data'] = $this->fetch("ajax/news");
        $return['page'] = page($list['count'], $limit, 'news');
        return json($return);
    }


    /**
     * @return array
     */
    public function place()
    {
        $this->assign('class', 2);
        $limit = $this->index_limit;
        $list = controller('data')->place(1, $limit);
        $this->assign('list', $list['data']);
        $this->assign('page', page($list['count'], $limit, 'place'));
        echo $this->fetch("place");
    }


    public function place_append()
    {
        $get = input();
        $limit = $this->index_limit;
        $list = controller('data')->place($get['page'], $limit);
        $this->assign('list', $list['data']);
        $return['data'] = $this->fetch("ajax/place");
        $return['page'] = page($list['count'], $limit, 'place');
        return json($return);
    }


    /**
     * @return array
     */
    public function price()
    {
        $this->assign('class', 3);
        $limit = $this->index_limit;
        $list = controller('data')->price(1, $limit);
        $this->assign('list', $list['data']);
        $this->assign('page', page($list['count'], $limit, 'price'));
        echo $this->fetch('price');
    }


    /**
     * @return array
     */
    public function price_append()
    {
        $get = input();
        $limit = $this->index_limit;
        $list = controller('data')->price($get['page'], $limit);
        $this->assign('list', $list['data']);
//        print_r( $list['data']);die;
        $return['data'] = $this->fetch("ajax/price");

        $return['page'] = page($list['count'], $limit, 'price');
        return json($return);
    }

    /**
     * @return array
     */
    public function line()
    {
        $this->assign('class', 4);
        $limit = $this->index_limit;
        $list = controller('data')->line(1, $limit);
//        dump($list);
        $this->assign('list', $list['data']);
        $this->assign('page', page($list['count'], $limit, 'line'));
        echo $this->fetch('route');
    }


    public function line_append()
    {
        $get = input();
        $limit = $this->index_limit;
        $list = controller('data')->line($get['page'], $limit);
        $this->assign('list', $list['data']);
//        print_r( $list['data']);die;
        $return['data'] = $this->fetch("ajax/line");
        $return['page'] = page($list['count'], $limit, 'line');
        return json($return);
    }


    /**
     * @return array
     */
    public function introduce()
    {
        $this->assign('class', 5);
        echo $this->fetch('introduce');
    }

    public function process()
    {
        $this->assign('class', 6);
        echo $this->fetch('process');
    }

    public function contact()
    {
        $this->assign('class', 7);
        echo $this->fetch('contact');
    }
}
